@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

REM AdvancedGraphicsCards Mod - Build and Deploy Script
REM Usage: build-and-deploy.bat

REM 配置变量
set PROJECT_NAME=AdvancedGraphicsCards
set PROJECT_DIR=%~dp0

REM 设置构建配置，默认为Debug
if not defined BUILD_CONFIG set "BUILD_CONFIG=Debug"

REM 根据构建配置设置输出目录
if /i "%BUILD_CONFIG%" == "Release" (
    set "BUILD_OUTPUT_DIR=%PROJECT_DIR%bin\Release\netstandard2.1"
) else (
    set "BUILD_OUTPUT_DIR=%PROJECT_DIR%bin\Debug\netstandard2.1"
)

if not defined STEAM_PATH set "STEAM_PATH=D:\Program Files (x86)\Steam"
set "MODS_DIR=%STEAM_PATH%\steamapps\common\Escape from Duckov\Duckov_Data\Mods"
set "TARGET_DIR=%MODS_DIR%\%PROJECT_NAME%"

echo ========================================
echo AdvancedGraphicsCards Mod - Build and Deploy
echo ========================================
echo.

REM Step 1: Build project
echo [1/3] Building project (%BUILD_CONFIG%)...
cd /d "%PROJECT_DIR%"
dotnet build "AdvancedGraphicsCards.csproj" -c %BUILD_CONFIG% 2>nul
if errorlevel 1 (
    echo ✗ Build failed! Continuing...
) else (
    echo ✓ Build successful!
)
echo.

REM Step 2: Check necessary files
echo [2/3] Checking necessary files...
set "DLL_FILE=%BUILD_OUTPUT_DIR%\%PROJECT_NAME%.dll"
set "CONFIG_DIR=%PROJECT_DIR%config"

if not exist "%DLL_FILE%" echo ✗ DLL file not found, skipping deployment
if not exist "%CONFIG_DIR%" echo ✗ Config directory not found, skipping deployment
echo ✓ File check completed
echo.

REM Step 3: Deploy to game Mods folder
echo [3/3] Deploying to game Mods folder...
if not exist "%TARGET_DIR%" mkdir "%TARGET_DIR%" 2>nul

if exist "%DLL_FILE%" (
    echo   Copying DLL file...
    copy /Y "%DLL_FILE%" "%TARGET_DIR%\" >nul 2>nul
)

if exist "%CONFIG_DIR%" (
    echo   Copying all files in config directory...
    xcopy /Y /E /I "%CONFIG_DIR%\*" "%TARGET_DIR%\" >nul 2>nul
)

echo.
echo ========================================
echo ✓ Deployment completed!
echo ========================================
echo.
echo Mod deployed to: %TARGET_DIR%
echo You can now enable this mod in the game!
echo.
